package com.ruoyi.project.channel.vwChannelWbCashDayStat.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.channel.channelAccountGroup.domain.ChannelAccountGroup;
import com.ruoyi.project.channel.channelAccountGroup.service.IChannelAccountGroupService;
import com.ruoyi.project.channel.payerPayType.domain.PayerPayType;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.vwChannelWbCashDayStat.domain.VwChannelWbCashDayStat;
import com.ruoyi.project.channel.vwChannelWbCashDayStat.service.IVwChannelWbCashDayStatService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * VIEW信息操作处理
 * 
 * @author CAIN
 * @date 2019-12-06
 */
@Controller
@RequestMapping("/channel/vwChannelWbCashDayStat")
public class VwChannelWbCashDayStatController extends BaseController
{
    private String prefix = "channel/view";
	@Autowired
	private IUserService userService;

	@Autowired
	private IVwChannelWbCashDayStatService vwChannelWbCashDayStatService;
	@Autowired
	private IChannelAccountGroupService channelAccountGroupService;

	@RequiresPermissions("channel:vwChannelWbCashDayStat:view")
	@GetMapping()
	public String vwChannelWbCashDayStat(ModelMap mmap)
	{
		PayerPayType search = new PayerPayType();
		search.setPayerUserName("系统自带");
		mmap.put("channels", userService.selectChannelList(new User()));

		ChannelAccountGroup channelAccountGroup = new ChannelAccountGroup();
		User user = getSysUser();
		String roleKey = ShiroUtils.getSysUser().getRoles().get(0).getRoleKey();
		List<ChannelAccountGroup> list = new ArrayList<>();
		if (roleKey.equals("channel")) {
			channelAccountGroup.setChannelId(user.getUserId());
			list = channelAccountGroupService.selectChannelAccountGroupList(channelAccountGroup);
		} else if (roleKey.equals("admin") || roleKey.equals("admin2")) {
			list = channelAccountGroupService.selectChannelAccountGroupList(channelAccountGroup);
		}
		mmap.put("groups", list);
	    return prefix + "/vwChannelWbCashDayStat";
	}
	
	/**
	 * 查询VIEW列表
	 */
	@RequiresPermissions("channel:vwChannelWbCashDayStat:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(VwChannelWbCashDayStat vwChannelWbCashDayStat)
	{
		startPage();
		User user = getSysUser();
		String roleKey = ShiroUtils.getSysUser().getRoles().get(0).getRoleKey();
		List<VwChannelWbCashDayStat> list = new ArrayList<>();
		if (roleKey.equals("channel")) {
			vwChannelWbCashDayStat.setUserId(user.getUserId());
			list = vwChannelWbCashDayStatService.selectVwChannelWbCashDayStatList(vwChannelWbCashDayStat);
		} else if (roleKey.equals("admin") || roleKey.equals("admin2")) {
			list = vwChannelWbCashDayStatService.selectVwChannelWbCashDayStatList(vwChannelWbCashDayStat);
		}
		return getDataTable(list);
	}
	
	
	/**
	 * 导出VIEW列表
	 */
	@RequiresPermissions("channel:vwChannelWbCashDayStat:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VwChannelWbCashDayStat vwChannelWbCashDayStat)
    {
		User user = getSysUser();
		String roleKey = ShiroUtils.getSysUser().getRoles().get(0).getRoleKey();
		List<VwChannelWbCashDayStat> list = new ArrayList<>();
		if (roleKey.equals("channel")) {
			vwChannelWbCashDayStat.setUserId(user.getUserId());
			list = vwChannelWbCashDayStatService.selectVwChannelWbCashDayStatList(vwChannelWbCashDayStat);
		} else if (roleKey.equals("admin") || roleKey.equals("admin2")) {
			list = vwChannelWbCashDayStatService.selectVwChannelWbCashDayStatList(vwChannelWbCashDayStat);
		}
        ExcelUtil<VwChannelWbCashDayStat> util = new ExcelUtil<VwChannelWbCashDayStat>(VwChannelWbCashDayStat.class);
        return util.exportExcel(list, "vwChannelWbCashDayStat");
    }
}
